package com.twilight.SofaStream;

import java.io.InputStream;
import java.util.ArrayList;

import com.twilight.SofaStream.R;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.net.Uri;
import android.net.Uri.Builder;


public class SofaPrefs extends PreferenceActivity {
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setTitle("Preferences");
        addPreferencesFromResource(R.xml.preferences);
        PreferenceScreen screen = getPreferenceScreen();
		RSSDB db = new RSSDB(this);
		ArrayList<RSSFeed> feeds = db.getFeeds();
		for (RSSFeed feed : feeds) {
			CheckBoxPreference pref = new CheckBoxPreference(this);
			pref.setTitle(feed.title);
			pref.setSummary(feed.description);
			String id = String.format("feed_%s", feed.id);
			pref.setKey(id);
	        screen.addPreference(pref);
	        if (feed.secure) {
	        	//Add username and password fields as children of this option...
	        	EditTextPreference unamePref = new EditTextPreference(this);
	        	unamePref.setTitle("Feed username");
	        	unamePref.setSummary(getResources().getString(R.string.username_description));
	        	unamePref.setKey(id + "_username");
	        	unamePref.setDialogTitle("Username");
		        screen.addPreference(unamePref);
	        	unamePref.setDependency(id);
	        	EditTextPreference passwdPref = new EditTextPreference(this);
	        	passwdPref.setTitle("Feed password");
	        	passwdPref.setSummary(getResources().getString(R.string.password_description));
	        	passwdPref.setKey(id + "_password");
	        	passwdPref.setDialogTitle("Password");
		        screen.addPreference(passwdPref);
		        passwdPref.setDependency(id);
	        }
		}
        
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
    }
    
}

